﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Lib.Utils;

namespace MS.INV.Reports
{
    public partial class InventoryStock : Lib.Bases.Forms.BaseForm
    {
        public InventoryStock()
        {
            InitializeComponent();
            dtTuNgay.EditValue = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
            dtDenNgay.EditValue = DateTime.Now;
        }

        private void InventoryStock_Load(object sender, EventArgs e)
        {
            try
            {
                using (SysObj.Kho_KiemKe kk = new SysObj.Kho_KiemKe())
                {
                    DateTime dt = kk.SmallThanNearest(DateTime.Now);
                    if (dt.Month == DateTime.Now.Month)
                        dtTuNgay.EditValue = dt.AddDays(1);
                }
            }
            catch (Exception ex)
            {
                Lib.Bases.SysError.RaiseError(ex, this.Name, "Load Form");
            }
        }

        private void btRef_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                using (SysObj.Inf_InventoryStock inf = new SysObj.Inf_InventoryStock("Report_Stock",
                      Cvert.ToShortDate(Convert.ToDateTime(dtTuNgay.EditValue)),
                      Cvert.ToShortDate(Convert.ToDateTime(dtDenNgay.EditValue))))
                {
                    grid.DataSource = inf.Excutive();
                }
            }
            catch (Exception ex)
            {
                Lib.Bases.SysError.RaiseError(ex, this.Name, "Load data");
            }
        }

        private void btClose_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.Close();
        }

        private void btPrint_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                Lib.Bases.Reports.ShowReport("Kho_TH_Ton.repx", grid.GetFilteredDataSource(), "TuNgay,DenNgay",
                    Convert.ToDateTime(dtTuNgay.EditValue).ToString("dd/MM/yyyy"),
                    Convert.ToDateTime(dtDenNgay.EditValue).ToString("dd/MM/yyyy"));
            }
            catch (Exception ex)
            {
                Lib.Bases.SysError.RaiseError(ex, this.Name, "Load data");
            }
        }
    }
}
